package com.rabbitmq.delay.producer;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

import static com.rabbitmq.delay.config.RabbitConfig.*;

/**
 * @author zhangwu
 * @create2021/6/16
 */
@Component
public class DelayMessageProducer {
    @Resource
    RabbitTemplate rabbitTemplate;

    public void send(String message,int delay){
        switch (delay){
            case 1:
                rabbitTemplate.convertAndSend(DELAY_EXCHANGE_NAME,DELAY_QUEUE_A_ROUTINGKEY,message);
                break;
            case 2:
                rabbitTemplate.convertAndSend(DELAY_EXCHANGE_NAME,DELAY_QUEUE_B_ROUTINGKEY,message);
                break;
        }
    }
}
